﻿
--/* Add non-clustered index on MailID column */
--IF EXISTS ( SELECT 1 FROM sys.indexes WHERE [object_id] = OBJECT_ID(N'[dbo].[TabMailList]') AND [name] = N'PK_TabReceiveMail' )
--BEGIN
    --ALTER TABLE [dbo].[TabMailList] DROP CONSTRAINT [PK_TabReceiveMail];
--END
--GO

--ALTER TABLE [dbo].[TabMailList] ADD CONSTRAINT [PK_TabReceiveMail] PRIMARY KEY NONCLUSTERED
--(
    --MailID ASC
--);
--GO


--/* Add clustered index on MailReceiver, MailFolderType, MailID */
--IF EXISTS ( SELECT 1 FROM sys.indexes WHERE [object_id] = OBJECT_ID(N'[dbo].[TabMailList]') AND [name] = N'IX_TabMailList_MailReceiver' )
--BEGIN
    --DROP INDEX [IX_TabMailList_MailReceiver] ON [dbo].[TabMailList];
--END
--GO
--CREATE CLUSTERED INDEX [IX_TabMailList_MailReceiver] ON dbo.TabMailList
--(
    --MailReceiver asc,
    --MailFolderType asc,
    --MailID desc
--);
--GO

/* We'll use UDS_MailXXX tables from now no. So delete the old tables */
IF ( OBJECT_ID(N'dbo.TabAccountInfo', N'U') IS NOT NULL )
	DROP TABLE dbo.TabAccountInfo;
GO

IF ( OBJECT_ID(N'dbo.TabExtMailAttachFiles', N'U') IS NOT NULL )
    DROP TABLE dbo.TabExtMailAttachFiles;
GO

IF ( OBJECT_ID(N'dbo.TabExtMailList', N'U') IS NOT NULL )
    DROP TABLE dbo.TabExtMailList;
GO

IF ( OBJECT_ID(N'dbo.TabExtMailLog', N'U') IS NOT NULL )
    DROP TABLE dbo.TabExtMailLog;
GO

IF ( OBJECT_ID(N'dbo.TabExtMailSendBuffer', N'U') IS NOT NULL )
    DROP TABLE dbo.TabExtMailSendBuffer;
GO

IF ( OBJECT_ID(N'dbo.TabExtMailSetting', N'U') IS NOT NULL )
    DROP TABLE dbo.TabExtMailSetting;
GO

IF ( OBJECT_ID(N'dbo.TabIntMailLog', N'U') IS NOT NULL )
    DROP TABLE dbo.TabIntMailLog;
GO

IF ( OBJECT_ID(N'dbo.TabMailAttachFiles', N'U') IS NOT NULL )
    DROP TABLE dbo.TabMailAttachFiles;
GO

IF ( OBJECT_ID(N'dbo.TabMailGrpMemb', N'U') IS NOT NULL )
    DROP TABLE dbo.TabMailGrpMemb;
GO

IF ( OBJECT_ID(N'dbo.TabMailGroup', N'U') IS NOT NULL )
    DROP TABLE dbo.TabMailGroup;
GO

IF ( OBJECT_ID(N'dbo.TabMailList', N'U') IS NOT NULL )
    DROP TABLE dbo.TabMailList;
GO

IF ( OBJECT_ID(N'dbo.TabSysMailFolder', N'U') IS NOT NULL )
    DROP TABLE dbo.TabSysMailFolder;
GO

IF ( OBJECT_ID(N'dbo.TabUsrMailFolder', N'U') IS NOT NULL )
    DROP TABLE dbo.TabUsrMailFolder;
GO

IF ( OBJECT_ID(N'dbo.TabAccountIndex', N'U') IS NOT NULL )
    DROP TABLE dbo.TabAccountIndex;
GO
